<template>
  <div class="index-container">
    <!-- 免费直播 -->
    <van-list :loading="loading" :finished="finished" finished-text="暂时没有更多了哦~" @load="onLoad">
      <van-grid :gutter="15" :border="false" :column-num="2">
        <van-grid-item v-for="(item, index) in List" :key="index" @click="toFreeDetai(item)">
          <van-image width="100%" height="105" :src="item.cover" />
          <div class="content">
            <h3 class="title">{{ item.name }}</h3>
            <div class="jiage">{{ item.lesson_num }}课时</div>
            <div class="xuexi">{{ item.init_book_num }}人已学习</div>
          </div>
        </van-grid-item>
      </van-grid>
    </van-list>
  </div>
</template>

<script>
import { getGoodsLists } from '@/api/goods/free'
export default {
  data() {
    return {
      active: 0,
      queryParams: {
        cate_id: null,
        page: 1,
        size: 10
      },
      groupsList: [],
      List: [],
      loading: false,
      finished: false
    }
  },

  computed: {},

  mounted() {
    this.queryParams.cate_id = this.$route.query.subject_id || 2
  },

  methods: {
    async onLoad() {
      this.loading = true
      await getGoodsLists(this.queryParams).then(res => {
        this.List = this.List.concat(res.data)
        this.queryParams.page = this.queryParams.page + 1
        if (res.data.length < 10) {
          this.finished = true
        }
      })
      this.loading = false
    },
    toFreeDetai(row) {
      this.$router.push({ path: '/free-details', query: { row: encodeURIComponent(JSON.stringify(row)) } })
    }
  }
}
</script>

<style lang="scss" scoped>
.index-container {
  background: #ffffff;
  ::v-deep .van-grid {
    margin-top: 20px;
    .van-grid-item {
      box-shadow: 0px 1.5px 4px 0px rgba(210, 212, 213, 0.2);
      border-radius: 5px;
    }
    .van-grid-item__content {
      box-shadow: 0px 1px 4px 0px rgba(210, 212, 213, 0.2);
      border-radius: 5px;
      padding: 0;
      overflow: hidden;
    }
    .content {
      box-sizing: border-box;
      width: 100%;
      padding: 8px 10px 10px;
      .title {
        font-size: 14px;
        font-weight: 600;
        color: #333333;
        line-height: 21px;
        @include textoverflow(1);
      }
      .jiage {
        font-size: 12px;
        color: #009697;
        line-height: 30px;
      }
      .xuexi {
        display: table;
        // margin-top: 10px;
        min-width: 75px;
        padding: 0 5px;
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        color: #11a8a4;
        background: rgba(7, 120, 121, 0.1);
        border-radius: 2px;
      }
      .van-button {
        width: 27px;
        height: 14px;
        background: #fd953f;
        padding: 0;
        vertical-align: bottom;
        .van-button__text {
          font-size: 14px;
          font-weight: bold;
          color: #fffefe;
        }
      }
      .open_price {
        font-size: 9px;
        font-weight: 800;
        color: #009697;
        // line-height: 30px;
      }
      .open_number {
        margin-left: 4px;
        line-height: 14px;
        font-size: 6px;
        font-weight: 500;
        text-decoration: line-through;
        color: #999999;
      }
    }
  }
}
</style>
